<template>
	<el-form ref="form" :model="form" label-width="80px">
		<el-form-item label="姓名">
			<el-input v-model="custom.name" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="客户来源">
			<el-select v-model="custom.source">
				<el-option label="电话介绍" value="电话销售"></el-option>
				<el-option label="转介绍" value="转介绍"></el-option>
				<el-option label="网络宣传" value="网络宣传"></el-option>
				<el-option label="线下宣传" value="线下销售"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="公司">
			<el-input v-model="custom.company"></el-input>
		</el-form-item>
		<el-form-item label="职位">
			<el-input v-model="custom.appointment"></el-input>
		</el-form-item>
		<el-form-item label="客户等级">
			<el-select v-model="custom.level">
				<el-option label="A" value="A"></el-option>
				<el-option label="B" value="B"></el-option>
				<el-option label="C" value="C"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="跟进状态">
			<el-select v-model="custom.followStatus">
				<el-option label="初次沟通" value="初次沟通"></el-option>
				<el-option label="方案报价" value="方案报价"></el-option>
				<el-option label="合同签订" value="合同签订"></el-option>
				<el-option label="回款结清" value="回款结清"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="介绍">
			<el-input type="textarea" v-model="custom.introduction"></el-input>
		</el-form-item>
		<el-form-item label="邮件">
			<el-input v-model="custom.email" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="地区">
			<el-input v-model="custom.district"></el-input>
		</el-form-item>
		<el-form-item label="信用代码">
			<el-input v-model="custom.creditCode" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="联系人">
			<el-input v-model="custom.contacts"></el-input>
		</el-form-item>
		<el-form-item label="性别">
			<el-input v-model="custom.sex" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="生日">
			<el-input v-model="custom.birthday" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="电话">
			<el-input v-model="custom.tel" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="意向产品">
			<el-input v-model="custom.intendedProducts"></el-input>
		</el-form-item>
		<el-form-item label="跟进时间">
			<el-input v-model="custom.followTime" disabled="true"></el-input>
		</el-form-item>
		<el-form-item label="介绍">
			<el-input type="textarea" v-model="custom.note"></el-input>
		</el-form-item>
		<el-form-item>
			<el-button type="primary" @click="onSubmit">修改客户信息</el-button>
			<el-button @click="back()">取消</el-button>
		</el-form-item>
	</el-form>
</template>


<script>
	export default {
		data() {
			return {
				userId: 0,
				customId: 0,
				custom: {}
				// name: '',
				// email: '',
				// creditCode: '',
				// sex: '',
				// birthday: '',
				// appointment: '',
				// tel: '',
				// followTime: '',
				// source: '',
				// company: '',
				// level: '',
				// followStatus: '',
				// introduction: '',
				// district: '',
				// contacts: '',
				// intendedProducts: '',
				// note: ''
			}
		},
		onLoad(options) {
			this.userId = uni.getStorageSync('id')
			this.customId = options.customId;
			console.log(this.userId + ' ' + this.customId);
			// 获取用户的客户详细信息
			uni.request({
				url: 'http://localhost:8089/crmdemo/custom/queryCustomById', //仅为示例，并非真实接口地址。
				data: {
					customId: this.customId
				},
				success: (res) => {
					console.log(res);
					if (res.data.status == "000000") {
						this.custom = res.data.result
					} else {
						this.$modal.msgError("获取客户详细信息失败")
					}
				}
			});
		},
		methods: {
			onSubmit() {
				function timestampToTime(timestamp) {
					var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
					var Y = date.getFullYear() + '-';
					var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
					var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
					var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
					var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
					var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
					return Y + M + D + h + m + s;
				}
				this.followTime = timestampToTime(this.followTime)
				// 新增回款信息
				uni.request({
					url: 'http://localhost:8089/crmdemo/custom/updateCustomInfo', //仅为示例，并非真实接口地址。
					data: {
						id: this.custom.id,
						source: this.custom.source,
						company: this.custom.company,
						level: this.custom.level,
						followStatus: this.custom.followStatus,
						introduction: this.custom.introduction,
						district: this.custom.district,
						contacts: this.custom.contacts,
						appointment: this.custom.appointment,
						intendedProducts: this.custom.intendedProducts,
						note: this.custom.note,
						name: this.custom.name,
						category: this.custom.category,
						email: this.custom.email,
						creditCode: this.custom.creditCode,
						sex: this.custom.sex,
						birthday: this.custom.birthday,
						tel: this.custom.tel,
						followTime: this.custom.followTime,
						userId: this.custom.userId
					},
					success: (res) => {
						console.log(res);
						if (res.data.status == "000000") {
							uni.showToast({
								title: "修改客户信息成功",
								duration: 2000
							})
							setTimeout(() => {
								uni.reLaunch({
									url: 'customDetail?customId='+this.customId
								})
							}, 2000)
						} else {
							this.$modal.msgError("修改客户信息失败")
						}
					}
				});
			},
			back(){
				uni.navigateTo({
					url: 'customDetail?customId='+this.customId
				})
			}
		}
	}
</script>


<style>

</style>